package com.example.shw

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.Gravity
import android.widget.Button
import android.widget.GridLayout

class CalculatorActivity : AppCompatActivity() {
    private var chars = arrayOf("7", "8", "9", "➗",
        "4", "5", "6", "x",
        "1", "2", "3", "-",
        ".", "0", "=", "+")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_calculator)
        val gridLayout = findViewById<GridLayout>(R.id.calculatorroot)
        for (i in chars.indices){
            val bn = Button(this)
            bn.text = chars[i]
            bn.textSize = 40F
            bn.setPadding(5, 35, 5, 35)
            val rowSpec = GridLayout.spec(i / 4 + 2)
            val columnSpec = GridLayout.spec(i % 4)
            val params = GridLayout.LayoutParams(rowSpec,columnSpec)
            params.setGravity(Gravity.FILL)
            gridLayout.addView(bn,params)
        }
    }
}